package com.wrial.simple;
/*
 * @Author  Wrial
 * @Date Created in 16:12 2020/3/29
 * @Description  N叉树的前序遍历
 */

import java.util.LinkedList;
import java.util.List;

public class LeetCode_589 {

    LinkedList<Integer> list = new LinkedList();
    public List<Integer> preorder(Node root) {
        if (root == null) return list;
         inList(root);
        return list;
    }

    // 递归方式
    private  void inList(Node root) {
        if (root == null) return;
        list.add(root.val);
        for (int i = 0; i < root.children.size(); i++) {
            inList(root.children.get(i));
        }
    }

    class Node {
        public int val;
        public List<Node> children;

        public Node() {}

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }
}
